﻿using ClockLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation.Collections;

namespace XiaoweiUWP.AppServiceResponseHandlers
{
    public static class ClockOperationResponseHandler
    {
        private enum ClockOpt
        {
            Add = 1,
            Modify = 2,
            Delete = 3,
            DeleteAll = 4
        }
        public static ValueSet RequestClockOperate(ValueSet message)
        {
            try
            {
                ClockData clockData = new ClockData()
                {
                    Clock_id = (long)message["Clock_id"],
                    Clock_event = (string)message["Clock_event"],
                    Repeat_interval = (string)message["Repeat_interval"],
                    Repeat_type = (RepeatType)(int)message["Repeat_type"],
                    Service_type = (int)message["Service_type"],
                    Trig_time = (long)message["Trig_time"],
                };
                switch ((ClockOpt)message["opt"])
                {
                    case ClockOpt.Add:
                        ClockManager.Instance.AddClock(clockData);
                        break;
                    case ClockOpt.Modify:
                        ClockManager.Instance.AdjustClock(clockData.Clock_id, clockData);
                        break;
                    case ClockOpt.Delete:
                        ClockManager.Instance.RemoveClock(clockData.Clock_id);
                        break;
                    case ClockOpt.DeleteAll:
                        ClockManager.Instance.RemoveAll();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                Logger.Debug.WriteLine($"ClockOperationResponseHandler RequestClockOperate ex{ex}");
            }
            return null;
        }
    }
}
